//-----------------------------------------------------------------------
//<copyright file="BienBanNhapHangDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class BienBanNhapHangDAO : SQLDatabase, IBienBanNhapHangDAO
	{

		#region Create BienBanNhapHang methods

		public BienBanNhapHang CreateBienBanNhapHang(BienBanNhapHang bienBanNhapHang)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangInsert");
				AddOutParameter(command, "@MaBBNH", SqlDbType.NVarChar, bienBanNhapHang.MaBBNH);
				AddInParameter(command, "@SoHopDong", SqlDbType.NVarChar, bienBanNhapHang.SoHopDong);
				AddInParameter(command, "@NoiNhan", SqlDbType.NVarChar, bienBanNhapHang.NoiNhan);
				AddInParameter(command, "@NgayGioNhan", SqlDbType.DateTime, bienBanNhapHang.NgayGioNhan);
				AddInParameter(command, "@NgayGioKiem", SqlDbType.DateTime, bienBanNhapHang.NgayGioKiem);
				AddInParameter(command, "@KetQua", SqlDbType.NVarChar, bienBanNhapHang.KetQua);
				AddInParameter(command, "@NguoiDuyet", SqlDbType.NVarChar, bienBanNhapHang.NguoiDuyet);
				AddInParameter(command, "@KeToan", SqlDbType.NVarChar, bienBanNhapHang.KeToan);
				AddInParameter(command, "@ThuKho", SqlDbType.NVarChar, bienBanNhapHang.ThuKho);

				ExecuteNonQuery(command);
                bienBanNhapHang.MaBBNH = (string)GetParameterValue(command, "@MaBBNH");
				return bienBanNhapHang;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateBienBanNhapHangException", ex);
			}
		}

		#endregion

		#region Update BienBanNhapHang methods

		public void UpdateBienBanNhapHang(BienBanNhapHang bienBanNhapHang)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangUpdate");

				AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, bienBanNhapHang.MaBBNH);
				AddInParameter(command, "@SoHopDong", SqlDbType.NVarChar, bienBanNhapHang.SoHopDong);
				AddInParameter(command, "@NoiNhan", SqlDbType.NVarChar, bienBanNhapHang.NoiNhan);
				AddInParameter(command, "@NgayGioNhan", SqlDbType.DateTime, bienBanNhapHang.NgayGioNhan);
				AddInParameter(command, "@NgayGioKiem", SqlDbType.DateTime, bienBanNhapHang.NgayGioKiem);
				AddInParameter(command, "@KetQua", SqlDbType.NVarChar, bienBanNhapHang.KetQua);
				AddInParameter(command, "@NguoiDuyet", SqlDbType.NVarChar, bienBanNhapHang.NguoiDuyet);
				AddInParameter(command, "@KeToan", SqlDbType.NVarChar, bienBanNhapHang.KeToan);
				AddInParameter(command, "@ThuKho", SqlDbType.NVarChar, bienBanNhapHang.ThuKho);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateBienBanNhapHangException", ex);
			}
		}

		#endregion

		#region Delete BienBanNhapHang methods

		public void DeleteBienBanNhapHang(BienBanNhapHang bienBanNhapHang)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangDelete");

				AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, bienBanNhapHang.MaBBNH);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteBienBanNhapHangException", ex);
			}
		}

		#endregion

		#region Select methods

		#region GetAll BienBanNhapHang methods

		public BienBanNhapHangs GetAllBienBanNhapHang()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangGetList");
				BienBanNhapHangs Result = new BienBanNhapHangs();
				List<BienBanNhapHang> List = ExecuteQuery<BienBanNhapHang>(command,true);
				foreach(BienBanNhapHang item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllBienBanNhapHangException", ex);
			}
		}

		#endregion


		#region GetBienBanNhapHang methods

		public BienBanNhapHang GetBienBanNhapHangByID(string maBBNH)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanNhapHangGet");

				AddInParameter(command, "@maBBNH", SqlDbType.NVarChar, maBBNH);

				return ExecuteQuery<BienBanNhapHang>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetBienBanNhapHangBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
